package com.ssy.lingxi.order.entity;

import com.fasterxml.jackson.annotation.JsonBackReference;

import javax.persistence.*;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Objects;

/**
 * 订单营销活动使用记录
 * @author 万宁
 * @version 2.0.0
 * @date 2021-09-23
 */
@Entity
@Table(schema = "public", name = "ord_promotion", indexes = {@Index(name = "ord_promotion_order_product_id_idx", columnList = "order_product_id")})
public class OrderPromotionDO implements Serializable {
    private static final long serialVersionUID = 4454064504319326382L;

    /**
     * 主键Id
     */
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "ord_promotion_seq")
    @SequenceGenerator(sequenceName = "ord_promotion_seq", name = "ord_promotion_seq", allocationSize = 1)
    private Long id;

    /**
     * 多对一双向关联订单商品
     */
    @JsonBackReference
    @ManyToOne(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
    @JoinColumn(name = "order_product_id")
    private OrderProductDO product;

    /**
     * 营销活动记录Id
     */
    @Column
    private Long recordId;

    /**
     * （营销服务）营销活动Id
     */
    @Column
    private Long promotionId;

    /**
     * 营销活动名称
     */
    @Column(columnDefinition = "varchar(60)")
    private String name;

    /**
     * 营销活动类型，定义在 ActivityTypeEnum 中
     */
    @Column
    private Integer promotionType;

    /**
     * 营销活动归属类型，定义在 BelongTypeEnum 中
     */
    @Column
    private Integer belongType;

    /**
     * 营销活动起始时间
     */
    @Column(columnDefinition = "timestamp")
    private LocalDateTime startTime;

    /**
     * 营销活动结束时间
     */
    @Column(columnDefinition = "timestamp")
    private LocalDateTime expireTime;

    public Long getRecordId() {
        return recordId;
    }

    public void setRecordId(Long recordId) {
        this.recordId = recordId;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public OrderProductDO getProduct() {
        return product;
    }

    public void setProduct(OrderProductDO product) {
        this.product = product;
    }

    public Long getPromotionId() {
        return promotionId;
    }

    public void setPromotionId(Long promotionId) {
        this.promotionId = promotionId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getPromotionType() {
        return promotionType;
    }

    public void setPromotionType(Integer promotionType) {
        this.promotionType = promotionType;
    }

    public Integer getBelongType() {
        return belongType;
    }

    public void setBelongType(Integer belongType) {
        this.belongType = belongType;
    }

    public LocalDateTime getStartTime() {
        return startTime;
    }

    public void setStartTime(LocalDateTime startTime) {
        this.startTime = startTime;
    }

    public LocalDateTime getExpireTime() {
        return expireTime;
    }

    public void setExpireTime(LocalDateTime expireTime) {
        this.expireTime = expireTime;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }

        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        OrderPromotionDO that = (OrderPromotionDO) o;
        return Objects.equals(id, that.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }
}
